package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.vo.basic.request.OrderLrcVO;
import com.ssy.lingxi.order.model.vo.basic.request.OrderSeparateVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderCompleteVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderLrcDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderProcessDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.PayResultDetailVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerMergePayVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerPayResultVO;
import com.ssy.lingxi.order.model.vo.buyer.request.BuyerPointsOrderVO;
import com.ssy.lingxi.order.model.vo.buyer.response.BuyerPayResultDetailVO;
import com.ssy.lingxi.order.model.vo.mobile.request.BuyerOrderVO;
import com.ssy.lingxi.order.model.vo.vendor.request.AgentPurchaseOrderVO;
import com.ssy.lingxi.order.service.web.IOrderCreationService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 订单能力 - 所有订单创建相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/order/create")
public class OrderCreationController {
    @Resource
    private IOrderCreationService orderCreationService;

    /**
     * “进货单” - 判断是否可以合并下单
     * @param headers HttpHeaders信息
     * @param separateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/check", method = RequestMethod.POST)
    public Wrapper<Void> checkOrderMergeCondition(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderSeparateVO separateVO) {
        return orderCreationService.checkOrderMergeCondition(headers, separateVO);
    }

    /**
     * 企业商城、渠道商城首页 - 订单创建之前，查询支付方式和支付渠道信息
     * @param headers HttpHeader信息
     * @param separateVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/payment/find", method = RequestMethod.POST)
    public Wrapper<OrderProcessDetailVO> findOrderProcessPaymentSetting(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderSeparateVO separateVO) {
        return orderCreationService.findOrderProcessPaymentSetting(headers, separateVO);
    }

    /**
     * “进货单下单” - 创建订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/buyer", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createBuyerOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerOrderVO orderVO) {
        return orderCreationService.createBuyerOrder(headers, orderVO);
    }

    /**
     * 代客下单 - 进货单下单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/agent/purchase", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createAgentPurchaseOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid AgentPurchaseOrderVO orderVO) {
        return orderCreationService.createAgentPurchaseOrder(headers, orderVO);
    }

    /**
     * Web - 创建拼团订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 创建结果
     */
    @RequestMapping(value = "/group", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createGroupOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerOrderVO orderVO) {
        return orderCreationService.createGroupOrder(headers, orderVO);
    }

    /**
     * 积分商城 - 创建积分订单
     * @param headers HttpHeader信息
     * @param orderVO 接口参数
     * @return 创建结果
     */
    @RequestMapping(value = "/points", method = RequestMethod.POST)
    public Wrapper<OrderCompleteVO> createPointsOrder(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerPointsOrderVO orderVO) {
        return orderCreationService.createPointsOrder(headers, orderVO);
    }

    /**
     * 订单支付
     * @param headers HttpHeader信息
     * @param payVO 接口参数
     * @return 支付链接（在线支付）
     */
    @RequestMapping(value = "/buyer/pay", method = RequestMethod.POST)
    public Wrapper<PayResultDetailVO> orderPay(@RequestHeader HttpHeaders headers, @RequestBody @Valid BuyerMergePayVO payVO) {
        return orderCreationService.orderPay(headers, payVO);
    }

    /**
     * 查询支付结果
     * @param headers HttpHeader信息
     * @param resultVO 接口参数
     * @return 支付结果
     */
    @RequestMapping(value = "/buyer/pay/result", method = RequestMethod.GET)
    public Wrapper<BuyerPayResultDetailVO> findPayResult(@RequestHeader HttpHeaders headers, @Valid BuyerPayResultVO resultVO) {
        return orderCreationService.findPayResult(headers, resultVO);
    }


    /**
     * “进货单”-待结算订单-查询积分列表
     * @param headers HttpHeader信息
     * @param lrcVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lrc/list", method = RequestMethod.POST)
    public Wrapper<List<OrderLrcDetailVO>> getLrcList(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderLrcVO lrcVO) {
        return orderCreationService.getLrcList(headers, lrcVO);
    }

    /**
     * “进货单”-待结算订单-查询积分列表
     * @param headers HttpHeader信息
     * @param lrcVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/agent/lrc/list", method = RequestMethod.POST)
    public Wrapper<List<OrderLrcDetailVO>> getLrcListByAgent(@RequestHeader HttpHeaders headers, @RequestBody @Valid OrderLrcVO lrcVO) {
        return orderCreationService.getLrcListByAgent(headers, lrcVO);
    }
}
